<?php
/*
 * Listet alle Serien auf..
 */
require_once('Database/Database.php');

$db = new Database();
$db->Connect();

try
{
    $data = $db->Select('Series');
}
catch(Exception $ex)
{
    echo 'No series found.<br /><br />';
    echo $ex;
    $db->Disconnect();
}
?>

<!DOCTYPE html>
<html>
    <head>
        <title>Alle Serien</title>
        <link rel="stylesheet" type="text/css" href="css/default.css" />
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    </head>
    <body>
        <div id="header">HEADER</div>
        <div id="list">
        <table>
        <tr>
        <td>Serie</td>
        <td>Kürzel</td>
        <td>Liga</td>
        <td>Maximale Fahrer</td>
        <td>Maximale Fahrer pro Team</td>
        <td>Ändern</td>
        <td>Löschen</td>
        </tr>
        <?php
        $edit_icon   = 'Icons/edit.png';
        $edit_link   = 'Series/edit.php';
        $delete_icon = 'Icons/delete.png';
        $delete_link = 'Series/delete.php';

        if($data != null)
        {
            foreach($data as $d)
            {
                $edit_string   = '<td><a href="' . $edit_link . '?id=' . $d->ID_Series .
                    '" target="_blank"><img src="' . $edit_icon . '"></img></a></td>';
            
                $delete_string = '<td><a href="' . $delete_link . '?id=' . $d->ID_Series .
                    '" target="_blank"><img src="' . $delete_icon . '"></img></a></td>';

                $name_string = '<td><a href="Series/Admin/index.php?id=' . $d->ID_Series . '" target="_blank">' . $d->Name . '</a></td>';

                echo '<tr>';
                echo $name_string;
                echo '<td>' . $d->Shortcut . '</td>';
                echo '<td>'; // Liga herausfinden
                $linked_league = $db->Select('Leagues', 'ID_League = ' . $d->League_ID);
                echo '<a href="Leagues/edit.php?id=' . $d->League_ID . '" target="_blank">' . $linked_league[0]->Name . '</a>';
                echo '</td>';
                echo '<td>' . $d->Maximum_drivers . '</td>';
                echo '<td>' . $d->Maximum_drivers_per_team . '</td>';
                echo $edit_string;
                echo $delete_string;
                echo '</tr>';
            }
            $db->Disconnect();
        }
        else
        {
            echo 'Keine Serie';
        }
        ?>
        </table>
        </div>
    </body>
</html>